<% layout('/layouts/default.html', {title: '资方结算单管理', libs: ['validate','dataGrid']}){ %>
<div class="main-content">
	<div class="box box-main">
		<div class="box-header with-border">
			<div class="box-title">
				<i class="fa icon-note"></i> ${text('资方结算单详情')}
			</div>
			<div class="box-tools pull-right">
				<% if(hasPermi('settlement:investorsettlement:investorSettlement:check')){ %>
					<button type="button" class="btn btn-sm btn-primary" id="btnC" onclick="finCheck()">${text('财务复核')}</button>&nbsp;
				<% } %>
				<button type="button" class="btn btn-box-tool" data-widget="collapse"><i class="fa fa-minus"></i></button>
			</div>
		</div>
		<#form:form id="inputForm" model="${investorSettlement}" action="${ctx}/settlement/investorsettlement/investorSettlement/save" method="post" class="form-horizontal">
		<div class="box-body">
			<div class="row" id="finBox" style="display:none">
				<h4 class="form-unit">${text('财务复核信息')}</h4>
				<div class="col-xs-6">
					<div class="form-group">
						<label class="control-label col-sm-4" title="">
							<span class="required hide">*</span> ${text('财务复核信息')}：<i class="fa icon-question hide"></i></label>
						<div class="col-sm-8">
							<#form:textarea path="financialReviewMemo" rows="4" maxlength="255" class="form-control"/>
						</div>
					</div>
				</div>
				<div class="col-xs-6">
					<div class="form-group">
						<button type="button" class="btn btn-sm btn-primary" id="btnT" onclick="finCheckSubmit()">${text('财务复核提交')}</button>&nbsp;
					</div>
				</div>
			</div>
			<div class="form-unit">${text('基本信息')}</div>
			<#form:hidden path="investorSettlementId"/>
			<#form:hidden path="serviceOrderId"/>
			<div class="row">
				<div class="col-xs-6">
					<div class="form-group">
						<label class="control-label col-sm-4" title="">
							<span class="required hide">*</span> ${text('编号')}：<i class="fa icon-question hide"></i></label>
						<div class="col-sm-8">
							<#form:input path="investorSettlementCode" maxlength="100" class="form-control" readonly="true"/>
						</div>
					</div>
				</div>
				<div class="col-xs-6">
					<div class="form-group">
						<label class="control-label col-sm-4" title="">
							<span class="required hide">*</span> ${text('资方')}：<i class="fa icon-question hide"></i></label>
						<div class="col-sm-8">
							<#form:input path="investorName"  class="form-control required" readonly="true"/>
						</div>
					</div>
				</div>
				<div class="col-xs-6">
					<div class="form-group">
						<label class="control-label col-sm-4" title="">
							<span class="required hide">*</span> ${text('结算日期')}：<i class="fa icon-question hide"></i></label>
						<div class="col-sm-8">
							<#form:input path="date" readonly="true" maxlength="20" class="form-control laydate"
							dataFormat="date" data-type="date" data-format="yyyy-MM-dd" disabled="true"/>
						</div>
					</div>
				</div>
				<div class="col-xs-6">
					<div class="form-group">
						<label class="control-label col-sm-4" title="">
							<span class="required hide">*</span> ${text('服务订单')}：<i class="fa icon-question hide"></i></label>
						<div class="col-sm-8">
							<#form:input path="serviceOrderCode" maxlength="64" class="form-control" readonly="true"/>
						</div>
					</div>
				</div>
				<div class="col-xs-6">
					<div class="form-group">
						<label class="control-label col-sm-4" title="">
							<span class="required hide">*</span> ${text('信用证')}：<i class="fa icon-question hide"></i></label>
						<div class="col-sm-8">
							<#form:input path="letterCreditCode" maxlength="100" class="form-control" readonly="true"/>
						</div>
					</div>
				</div>
				<div class="col-xs-6">
					<div class="form-group">
						<label class="control-label col-sm-4" title="">
							<span class="required hide">*</span> ${text('年度汽车买卖协议')}：<i class="fa icon-question hide"></i></label>
						<div class="col-sm-8">
							<#form:input path="yearCarSalePurchaseAgreementCode" maxlength="100" class="form-control" readonly="true"/>
						</div>
					</div>
				</div>
				<div class="col-xs-6">
					<div class="form-group">
						<label class="control-label col-sm-4" title="">
							<span class="required hide">*</span> ${text('付款方式')}：<i class="fa icon-question hide"></i></label>
						<div class="col-sm-8">
							<#form:select path="paymentMethod" dictType="payment_method" blankOption="true" class="form-control" readonly="true"/>
						</div>
					</div>
				</div>
				<div class="col-xs-6">
					<div class="form-group">
						<label class="control-label col-sm-4" title="">
							<span class="required hide">*</span> ${text('预付款余额')}：<i class="fa icon-question hide"></i></label>
						<div class="col-sm-8">
							<#form:input path="prepaymentBalance" class="form-control number" readonly="true"/>
						</div>
					</div>
				</div>
				<div class="col-xs-6">
					<div class="form-group">
						<label class="control-label col-sm-4" title="">
							<span class="required hide">*</span> ${text('是否财务复核')}：<i class="fa icon-question hide"></i></label>
						<div class="col-sm-8">
							<#form:radio path="financialReviewFlag" dictType="sys_yes_no" class="form-control" disabled="true"/>
						</div>
					</div>
				</div>
			</div>
			<div class="row">
				<div class="col-xs-12">
					<div class="form-group">
						<label class="control-label col-sm-2" title="">
							<span class="required hide">*</span> ${text('备注信息')}：<i class="fa icon-question hide"></i></label>
						<div class="col-sm-10">
							<#form:textarea path="remarks" rows="4" maxlength="500" class="form-control" readonly="true"/>
						</div>
					</div>
				</div>
			</div>
			<!--
            <div class="row">
                <div class="col-xs-6">
                    <div class="form-group">
                        <label class="control-label col-sm-4" title="">
                            <span class="required hide">*</span> ${text('财务复核')}：<i class="fa icon-question hide"></i></label>
                        <div class="col-sm-8">
                            <#form:textarea path="financialReviewMemo" rows="4" maxlength="255" class="form-control"/>
                        </div>
                    </div>
                </div>
            </div>
            -->
			<h4 class="form-unit">${text('合计信息')}</h4>
			<div class="ml10 mr10">
				<table id="investorSettlementDetailDataGrid"></table>
			</div>
			<h4 class="form-unit">${text('预付款信息')}</h4>
			<div class="ml10 mr10">
				<table id="investorSettlementPrepaymentDataGrid"></table>
			</div>
			<h4 class="form-unit">${text('付款明细信息')}</h4>
			<div class="ml10 mr10">
				<table id="investorSettlementPaymentDataGrid"></table>
			</div>
			<h4 class="form-unit">${text('系统信息')}</h4>
			<div class="col-xs-6">
				<div class="form-group">
					<label class="control-label col-sm-4" title="">
						<span class="required hide">*</span> ${text('创建者')}：<i class="fa icon-question hide"></i></label>
					<div class="col-sm-8">
						<#form:input path="createBy" maxlength="64" class="form-control" disabled="true"/>
					</div>
				</div>
			</div>
			<div class="col-xs-6">
				<div class="form-group">
					<label class="control-label col-sm-4" title="">
						<span class="required hide">*</span> ${text('创建时间')}：<i class="fa icon-question hide"></i></label>
					<div class="col-sm-8">
						<#form:input path="createDate" readonly="true" maxlength="20" class="form-control" disabled="true"
						dataFormat="date" data-type="date" data-format="yyyy-MM-dd"/>
					</div>
				</div>
			</div>
			<div class="col-xs-6">
				<div class="form-group">
					<label class="control-label col-sm-4" title="">
						<span class="required hide">*</span> ${text('更新者')}：<i class="fa icon-question hide"></i></label>
					<div class="col-sm-8">
						<#form:input path="updateBy" maxlength="64" class="form-control" disabled="true"/>
					</div>
				</div>
			</div>
			<div class="col-xs-6">
				<div class="form-group">
					<label class="control-label col-sm-4" title="">
						<span class="required hide">*</span> ${text('更新时间')}：<i class="fa icon-question hide"></i></label>
					<div class="col-sm-8">
						<#form:input path="updateDate" readonly="true" maxlength="20" class="form-control" disabled="true"
						dataFormat="date" data-type="date" data-format="yyyy-MM-dd"/>
					</div>
				</div>
			</div>
		</div>
		<div class="box-footer">
			<div class="row">
				<div class="col-sm-offset-2 col-sm-10">
					<button type="button" class="btn btn-sm btn-default" id="btnCancel" onclick="js.closeCurrentTabPage()"><i class="fa fa-reply-all"></i> ${text('关 闭')}</button>
				</div>
			</div>
		</div>
	</#form:form>
</div>
</div>
<% } %>
<script>
	//初始化资方结算单付款DataGrid对象
	$("#investorSettlementPaymentDataGrid").dataGrid({

		data: ${toJson(investorSettlement.investorSettlementPaymentList)},
		datatype: "local", // 设置本地数据
		autoGridHeight: function(){return 'auto'}, // 设置自动高度

		// 设置数据表格列
		columnModel: [
			{header:'状态', name:'status', editable:false, hidden:true},
			{header:'主键', name:'investorSettlementPaymentId', editable:false, hidden:true},
			{header:'${text("车辆")}', name:'carId', width:150, editable:false, edittype:'text', editoptions:{'maxlength':'64', 'class':'form-control'}},
			{header:'${text("车架号")}', name:'frameNumber', width:150, editable:false, edittype:'text', editoptions:{'maxlength':'100', 'class':'form-control'}},
			{header:'${text("付款单号")}', name:'paymentCode', width:150, editable:false, edittype:'text', editoptions:{'maxlength':'100', 'class':'form-control'}},
			{header:'${text("费用项目")}', name:'expenseItem', width:150, editable:false, edittype:'text', editoptions:{'maxlength':'2', 'class':'form-control'}},
			{header:'${text("实付金额")}', name:'actualAmount', width:150, editable:false, edittype:'text', editoptions:{'class':'form-control number'}},
			{header:'${text("是否是核销预付款")}', name:'ifFlag', width:100,
				editable:true, edittype:'select', editoptions:{'class':'form-control',
					items: $.merge([{dictLabel:'&nbsp;',dictValue:''}], ${@DictUtils.getDictListJson('sys_yes_no')}),
					itemLabel: 'dictLabel', itemValue: 'dictValue', dataInit: function(element){
						$(element).select2().on("change",function(){$(this).resetValid()});
					},
					disabled:true
				}
			},
			{header:'${text("资方结算单ID")}', name:'investorSettlementId.investorSettlementId', editable:true, hidden:true}
		],

		showFooter:true,

		// 编辑表格参数
		editGrid: true,				// 是否是编辑表格
		editGridInitRowNum: 1,		// 编辑表格的初始化新增行数
		editGridAddRowBtn: $('#investorSettlementPaymentDataGridAddRowBtn'),	// 子表增行按钮
		editGridAddRowInitData: {investorSettlementPaymentId: '', status: Global.STATUS_NORMAL},	// 新增行的时候初始化的数据

		// 编辑表格的提交数据参数
		editGridInputFormListName: 'investorSettlementPaymentList', // 提交的数据列表名
		editGridInputFormListAttrs: 'status,investorSettlementPaymentId,carId,frameNumber,paymentCode,expenseItem,actualAmount,ifFlag,investorSettlementId.investorSettlementId,', // 提交数据列表的属性字段

		// 加载成功后执行事件
		ajaxSuccess: function(data){
			// 设置底部合计行数据(设置合计行)
			$('#investorSettlementPaymentDataGrid').dataGrid("footerData", "set", {
				'expenseItem' : '合计：',
				'actualAmount': "${actualAmountTotalPayment}"
			}, false);
		}
	});
	//初始化资方结算单预付款DataGrid对象
	$("#investorSettlementPrepaymentDataGrid").dataGrid({

		data: ${toJson(investorSettlement.investorSettlementPrepaymentList)},
		datatype: "local", // 设置本地数据
		autoGridHeight: function(){return 'auto'}, // 设置自动高度

		// 设置数据表格列
		columnModel: [
			{header:'状态', name:'status', editable:false, hidden:true},
			{header:'主键', name:'investorSettlementPrepaymentId', editable:false, hidden:true},
			{header:'${text("预付款单号")}', name:'prepaymentCode', width:150, editable:false, edittype:'text', editoptions:{'maxlength':'100', 'class':'form-control'}},
			{header:'${text("预付款类型")}', name:'prepaymentType', width:100,
				editable:false, edittype:'text'
			},
			{header:'${text("金额")}', name:'amount', width:150, editable:false, edittype:'text', editoptions:{'class':'form-control number'}},
			{header:'${text("已核销金额")}', name:'verificationAmount', width:150, editable:false, edittype:'text', editoptions:{'class':'form-control number'}},
			{header:'${text("剩余金额")}', name:'remainingAmount', width:150, editable:false, edittype:'text', editoptions:{'class':'form-control number'}},
			{header:'${text("资方结算单ID")}', name:'investorSettlementId.investorSettlementId', editable:false, hidden:true}
		],

		// 编辑表格参数
		editGrid: true,				// 是否是编辑表格
		editGridInitRowNum: 1,		// 编辑表格的初始化新增行数
		editGridAddRowBtn: $('#investorSettlementPrepaymentDataGridAddRowBtn'),	// 子表增行按钮
		editGridAddRowInitData: {investorSettlementPrepaymentId: '', status: Global.STATUS_NORMAL},	// 新增行的时候初始化的数据

		// 编辑表格的提交数据参数
		editGridInputFormListName: 'investorSettlementPrepaymentList', // 提交的数据列表名
		editGridInputFormListAttrs: 'status,investorSettlementPrepaymentId,prepaymentCode,prepaymentType,amount,verificationAmount,remainingAmount,investorSettlementId.investorSettlementId,', // 提交数据列表的属性字段

		// 加载成功后执行事件
		ajaxSuccess: function(data){

		}
	});
	//初始化资方结算单明细DataGrid对象
	$("#investorSettlementDetailDataGrid").dataGrid({

		data: ${toJson(investorSettlement.investorSettlementDetailList)},
		datatype: "local", // 设置本地数据
		autoGridHeight: function(){return 'auto'}, // 设置自动高度

		// 设置数据表格列
		columnModel: [
			{header:'状态', name:'status', editable:false, hidden:true},
			{header:'主键', name:'investorSettlementDetailId', editable:false, hidden:true},
			{header:'${text("车辆")}', name:'carId', width:150, editable:false, edittype:'text', editoptions:{'maxlength':'64', 'class':'form-control'}},
			{header:'${text("车架号")}', name:'frameNumber', width:150, editable:false, edittype:'text', editoptions:{'maxlength':'100', 'class':'form-control'}},
			{header:'${text("车价")}', name:'price', width:150, editable:false, edittype:'text', editoptions:{'class':'form-control number'}},
			{header:'${text("币种")}', name:'currency', width:100,
				editable:true, edittype:'select', editoptions:{'class':'form-control',
					items: $.merge([{dictLabel:'&nbsp;',dictValue:''}], ${@DictUtils.getDictListJson('sys_bizhong')}),
					itemLabel: 'dictLabel', itemValue: 'dictValue', dataInit: function(element){
						$(element).select2().on("change",function(){$(this).resetValid()});
					},
					disabled:true
				}
			},
			{header:'${text("预计汇率")}', name:'estimateExchangeRate', width:150, editable:false, edittype:'text', editoptions:{'maxlength':'10', 'class':'form-control'}},
			{header:'${text("实际汇率")}', name:'actualExchangeRate', width:150, editable:false, edittype:'text', editoptions:{'maxlength':'10', 'class':'form-control'}},
			{header:'${text("应付总金额")}', name:'payableAmount', width:150, editable:false, edittype:'text', editoptions:{'class':'form-control number'}},
			{header:'${text("实付总金额")}', name:'actualAmount', width:150, editable:false, edittype:'text', editoptions:{'class':'form-control number'}},
			{header:'${text("资方结算单ID")}', name:'investorSettlementId.investorSettlementId', editable:false, hidden:true}
		],

		showFooter: true,

		// 编辑表格参数
		editGrid: true,				// 是否是编辑表格
		editGridInitRowNum: 1,		// 编辑表格的初始化新增行数
		editGridAddRowBtn: $('#investorSettlementDetailDataGridAddRowBtn'),	// 子表增行按钮
		editGridAddRowInitData: {investorSettlementDetailId: '', status: Global.STATUS_NORMAL},	// 新增行的时候初始化的数据

		// 编辑表格的提交数据参数
		editGridInputFormListName: 'investorSettlementDetailList', // 提交的数据列表名
		editGridInputFormListAttrs: 'status,investorSettlementDetailId,carId,frameNumber,price,currency,estimateExchangeRate,actualExchangeRate,payableAmount,actualAmount,investorSettlementId.investorSettlementId,', // 提交数据列表的属性字段

		// 加载成功后执行事件
		ajaxSuccess: function(data){
			// 设置底部合计行数据(设置合计行)
			$('#investorSettlementDetailDataGrid').dataGrid("footerData", "set", {
				'actualExchangeRate' : '合计：',
				'payableAmount': "${payableAmountTotal}",
				'actualAmount': "${actualAmountTotal}"
			}, false);
		}
	});
</script>
<script>
$("#inputForm").validate({
	submitHandler: function(form){
		js.ajaxSubmitForm($(form), function(data){
			js.showMessage(data.message);
			if(data.result == Global.TRUE){
				js.closeCurrentTabPage(function(contentWindow){
					contentWindow.page();
				});
			}
		}, "json");
    }
});
$(function(){
	let num= $("#prepaymentBalance").val();
	$("#prepaymentBalance").val(parseFloat(num));
	let financialReviewFlag = $("#financialReviewFlag").val();
	if(financialReviewFlag == "1" || financialReviewFlag == 1){
		$("#btnC").css("display","none");
	}
});
function finCheck(){
	$("#finBox").css("display","block");
}
function finCheckSubmit(){
	let investorSettlementId = $("#investorSettlementId").val();
	let financialReviewMemo = $("#financialReviewMemo").val();
	if(financialReviewMemo == null || financialReviewMemo == "") {
		js.showErrorMessage("财务复核信息未填写");
		return false;
	}
	$.ajax({
		type: "post",
		url: "${ctx}/settlement/investorsettlement/investorSettlement/finCheckSave",
		data: {investorSettlementId: investorSettlementId,financialReviewMemo:financialReviewMemo},
		dataType: "json",
		success: function (data) {
			if(data == ""){
				js.showErrorMessage("财务复核失败");
				return false;
			}
			js.closeCurrentTabPage();
		}
	});
}
</script>
